//导入 mongoose
const mongoose = require('mongoose');
const Goods = require("./productModel")
const charGoods = require("./characteristicProductModel")
//创建文档的结构对象
//设置集合中文档的属性以及属性值的类型
let orderSchema = new mongoose.Schema({
    userName: String,
    orderNumber: String,
    status: { type: String, enum: ["已取消","待支付","待发货","待收货","已完成"],default:'待支付' },
    items: [
        {
            productId: { type: mongoose.Schema.Types.ObjectId,ref:Goods},
            charProductId:{type: mongoose.Schema.Types.ObjectId,ref:charGoods},
            quantity: Number,
            price: Number
        }
    ],
    totalPrice: Number,
    createdAt: String,
    userAddr:{}
});

//创建模型对象  对文档操作的封装对象
let orderModel = mongoose.model('order', orderSchema);

//暴露模型对象
module.exports = orderModel;
